Skip to content

ao_two_e_ints: exact (ik|ik) Schwartz diagonals on the map path (finish #419) - #423

Merged
scemama merged 3 commits into
QuantumPackage:dev-stablefrom
scemama:issue419-map-diagonals
Nov 19, 2026
Merged

scemama merged 3 commits into
QuantumPackage:dev-stablefrom
scemama:issue419-map-diagonals

Conversation

@scemama

@scemama scemama commented Nov 19, 2026

Copy link
Copy Markdown
Member

Issue #419 was reopened on 2026-11-19 because the merge of PR #422 (fd7faae,
merged as 66de718) left one defect: on the map path (do_ao_cholesky = False)
the dispatcher ao_two_e_integral routes to ao_two_e_integral_schwartz_accel
whenever nprim(i)*nprim(j)*nprim(k)*nprim(l) > 1024, and that accelerator
skips primitive quartets with the absolute threshold
ao_integrals_threshold**2. The Schwartz screening factors
ao_two_e_integral_schwartz(i,k) = sqrt((ik|ik)) were therefore computed from
zeroed (or under-summed) diagonals, and the AO-level CS test then dropped
integrals far above the threshold. Measured on the reopened issue, threshold
1e-15, do_ao_cholesky = False:

  • (H2O)4 chain cc-pVDZ: 43/5050 (ik|ik) factors exactly 0 (exact > 0),
    34 482 integrals >= 1e-15 dropped, largest 3.9e-9
  • Kr2 cc-pVDZ: 141/1711, 47 948, 9.4e-8

The Cholesky path was unaffected (do_schwartz_accel is false when
do_ao_cholesky). The same defect existed on the long-range (erf) path, which
routes to ao_two_e_integral_schwartz_accel_erf unconditionally above 1024
primitives.

Commits

  1. ao_two_e_ints: exact (ik|ik) Schwartz diagonals on the map path
    • New plain functions ao_two_e_integral_full / ao_two_e_integral_erf_full:
      verbatim move of the dispatcher's final branch (full primitive sum),
      so the dispatcher's last branch is a single call (no behaviour change
      on the Cholesky path: there the diagonals were already the full sum).
    • The providers ao_two_e_integral_schwartz and
      ao_two_e_integral_erf_schwartz now use dsqrt(dabs((i,k,i,k))) —
      the same pattern the cGTO providers use since cGTOs: rigorous Cauchy-Schwarz screening of the AO two-electron integrals #421.
  2. ao_two_e_integral_zero: drop the overlap product test
    Per the issue Proposal: the test ao_overlap_abs(j,l)ao_overlap_abs(i,k)
    < thr is not a bound on (ik|jl) (it dropped integrals up to ~10x the
    threshold, e.g. S_ik
    S_jl ~ 1e-15 with (ik|jl) = 1.1e-15); the rigorous
    CS bound with exact diagonals subsumes it at zero cost. The BEGIN_DOC is
    rewritten — this also restores the doc fix (integral is (ik|jl), bound
    sqrt((ik|ik)(jl|jl))) that merge 66de718 dropped from ao_two_e_ints: same-side Schwartz bound sqrt((ik|ik)) (fix #419) #422.
  3. tests: (H2O)4 chain regression test for the map-path Schwartz fix
    • New tests/input/h2o4_chain.xyz (the 4-water chain of the issue,
      O-O spacing 2.9 A) + 00.create.bats entry.
    • New 10.hf.bats test B-B_screening_map: do_ao_cholesky = False,
      threshold 1e-15; the map stores exactly the integrals >= threshold
      that pass the rigorous CS bound, so the printed count is
      deterministic and is the regression gate (the SCF energy moves by
      ~1e-10 only).
    • Regenerated docs/source/modules/ao_two_e_ints.rst (only the page whose
      sources changed; the new functions, the rewritten docstrings and the
      previously undocumented ao_two_e_integral_schwartz_cgtos provider).

Evidence (this branch, macmini arm64, cc-pVDZ, (H2O)4 chain, threshold 1e-15)

quantity pre-fix (dev-stable) post-fix
map count "Number of AO integrals" N0 = 3866749 N1 = 3916331
SCF energy, map path E0 = -304.1242786330997 E1 = -304.12427863337
SCF energy, default (Cholesky) path Eref = -304.124278633356 (unchanged)
zeroed (ik ik) factors, this test chain (5050) 881
  • The 43/5050 pre-fix figure above is the issue's own measurement on the
    reporter's chain; the same probe re-measured on this branch's test chain
    gives 881/5050 pre-fix and 0 post-fix (the diagonals are now the full
    primitive sum by construction).
  • N1 - N0 = 49 582 — the integrals previously dropped on this chain
    (34 482 on the issue's chain).
  • |E0 - E1| = 2.7e-10 Ha; post-fix the map path agrees with the Cholesky
    path (Eref) to 1.4e-11.
  • Removing the overlap test (commit 2) is count- and energy-neutral on this
    chain: every quartet it killed also fails the magnitude test.
  • 10.hf.bats: all 33 pre-existing tests pass before and after the fix with
    unchanged Cholesky-path energies (B-B -48.9950585434279,
    B-B_screening, HCN -92.88717500035233, ...); with the new test the suite
    is 34/34.

On the map path (do_ao_cholesky = False) the dispatcher
ao_two_e_integral routes to ao_two_e_integral_schwartz_accel
whenever the product of the primitive counts exceeds 1024, and
that accelerator skips primitive quartets with the absolute
threshold ao_integrals_threshold**2. The Schwartz screening
factors ao_two_e_integral_schwartz(i,k) = sqrt((ik|ik)) were
therefore computed from zeroed (or under-summed) diagonals, and
the AO-level CS test then dropped integrals far above the
threshold: on the (H2O)4 chain, cc-pVDZ, threshold 1e-15,
43/5050 factors came out exactly 0 and 34 482 integrals >= 1e-15
were dropped (largest 3.9e-9). The Cholesky path was unaffected
(do_schwartz_accel is false when do_ao_cholesky), which is why
the defect survived the sqrt((ik|ik)) fix of QuantumPackage#422.

The full primitive sum (the dispatcher's final branch, moved
verbatim) is now ao_two_e_integral_full, and the provider
ao_two_e_integral_schwartz uses
dsqrt(dabs(ao_two_e_integral_full(i,k,i,k))) - the same pattern
the cGTO providers use since QuantumPackage#421 (dabs: a vanishing diagonal
can be negative by rounding). Dispatcher behaviour is unchanged:
its last branch is now a single call.

The same defect existed on the long-range (erf) path, which
routes to ao_two_e_integral_schwartz_accel_erf unconditionally
above 1024 primitives; ao_two_e_integral_erf_full and
ao_two_e_integral_erf_schwartz get the same treatment.
Per the proposal in issue QuantumPackage#419: the test
ao_overlap_abs(j,l)*ao_overlap_abs(i,k) < ao_integrals_threshold
is not a bound on (ik|jl) - it dropped integrals up to ~10x the
threshold (5-8 bohr 1s example: S_ik*S_jl ~ 1e-15 while
(ik|jl) = 1.1e-15). The rigorous CS bound
sqrt((ik|ik)(jl|jl)) with exact diagonals (previous commit)
subsumes it at zero cost: the factors are already provided.

The BEGIN_DOC is rewritten: the integral tested is (ik|jl)
(1st+3rd arguments = pair 1, 2nd+4th = pair 2), the real-GTO
test is the rigorous Cauchy-Schwarz bound, and no integral
above ao_integrals_threshold is screened. This also restores
the doc fix that the merge 66de718 of QuantumPackage#422 dropped.
Closes the loop on issue QuantumPackage#419 with a deterministic regression
test for the map path (do_ao_cholesky = False) now that the
(ik|ik) Schwartz diagonals are exact.

Fixture: a 12-atom (H2O)4 chain (tests/input/h2o4_chain.xyz,
four water molecules at 2.9 A, cc-pVDZ), created by
00.create.bats like every other fixture. The chain geometry was
chosen so that many cross-molecule (ik|ik) diagonals are small:
it reproduces the issue's symptom on a system that SCFs in a few
seconds.

The test (B-B_screening_map in 10.hf.bats) runs the SCF with
do_ao_cholesky = False and ao_integrals_threshold = 1.0e-15 and
checks two things:
  - the map stores exactly 3916331 AO integrals. The count is
    the gate: with the exact diagonals it is deterministic,
    while the pre-fix accelerated path zeroed 881/5050 of the
    (ik|ik) diagonals on this chain (43/5050 on the issue's
    geometry) and the CS screening then dropped integrals far
    above the threshold;
  - the energy is -304.12427863337 (tolerance 1e-8), agreeing
    with the default Cholesky path (-304.124278633356) to
    1.4e-11.
io_ao_two_e_integrals is set to None: the "Write" mode of the
00.create fixture flips to "Read" after the first map dump, and
the read path prints no "Number of AO integrals" line; None
keeps the map computed on the fly on every run, which is the
mode the constants were recorded in.

Docs: docs/source/modules/ao_two_e_ints.rst is updated for the
rewritten and new docstrings (ao_two_e_integral_full,
ao_two_e_integral_erf_full, the ao_two_e_integral_schwartz
providers, ao_two_e_integral_zero) and gains the previously
undocumented ao_two_e_integral_schwartz_cgtos provider. Only the
page whose sources changed is touched; the unrelated drift a
local full regeneration would have introduced (module-prefixed
File: lines, needs lists of modules not built here) is kept out
of the diff.
@scemama
scemama merged commit 264d3e7 into QuantumPackage:dev-stable Nov 19, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant